package org.feng.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.quarkus.hibernate.orm.panache.PanacheEntityBase;

@Entity
public class Menu extends PanacheEntityBase {

    @Id
    @GeneratedValue
    public Integer menuId;

    public Integer parentId;

    @Transient
    @JsonIgnore
    private Menu parentMenu;
   /**
     * 获取父菜单
     * @returnparentId
     */
    @Transient
    public Menu getParentDept(boolean isRefresh) {
    	if (isRefresh || null==parentMenu) {
    		parentMenu=findById(parentId);
    	}
    	return parentMenu;
    }


    public void setParentMenu(Menu parentMenu) {
    	this.parentMenu = parentMenu;
    }

	public String menuName;

    public String url;

    public String perms;

    public Integer orderNum;

    @JsonIgnore
    public Date createTime;

    @JsonIgnore
    public Date modifyTime;

    //@JsonInclude(JsonInclude.Include.NON_NULL)
    public String checkArr = "0";

    //@JsonInclude(JsonInclude.Include.NON_EMPTY)
    @Transient
    public List<Menu> children;

    /**
     * 获取所有子部门
     * @param isRefresh true 表示从数据库中刷新数据 false 获取缓存数据
     * @return
     */
    public List<Menu> getChildren(boolean isRefresh){
    	if (isRefresh || null==children) {
    		children=list("parentId", menuId);
    		for (Menu dp : children) {
    			dp.setParentMenu(this);
    		}
    	}
    	return children;
    }
    
    
    @Transient
    public boolean isHasChild(){
    	getChildren(false);
    	return children.size()>0;
    }

    public String icon;

}